package view.cliente;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import model.cliente.Cliente;
import model.produto.Produto;

import com.towel.el.annotation.AnnotationResolver;
import com.towel.swing.table.ObjectTableModel;

import controller.produto.ProdutoController;

import view.PesquisaMae;
import view.utils.PainelBotoes;

public class ClientePesquisa extends PesquisaMae {

	private JLabel lbNome, lbCpf;
	private JTextField txNome, txCpf;

	private JTable grid;

	private JPanel painelNorte;
	private JPanel painelCentro;

	private ObjectTableModel<Cliente> tableModel;
	private AnnotationResolver resolver;

	private Cliente cliente;

	public ClientePesquisa(ActionListener controller) {
		super("Cliente", 480, 600, controller);

		init();
		setupLayout();
		setupComponentes();
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void init() {
		super.init();

		lbNome = new JLabel("Nome:");
		lbCpf = new JLabel("CPF:");

		txNome = new JTextField(25);
		txCpf = new JTextField(20);

		grid = new JTable(tableModel);

		painelNorte = new JPanel();
		painelCentro = new JPanel();
	}

	@Override
	protected void setupComponentes() {
		super.setupComponentes();
		
		JPanel aux1 = new JPanel(new GridLayout(2, 1));
		JPanel aux2 = new JPanel(new GridLayout(2, 1));
		JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
		JPanel aux4 = new JPanel(new FlowLayout(FlowLayout.LEFT));

		

		aux1.add(lbNome);
		aux1.add(lbCpf);

		aux3.add(txNome);
		aux4.add(txCpf);

		aux2.add(aux3);
		aux2.add(aux4);

		painelNorte.add(aux1, BorderLayout.WEST);
		painelNorte.add(aux2, BorderLayout.CENTER);

		painelCentro.add(new JScrollPane(grid));

		getPainelForm().add(painelNorte, BorderLayout.NORTH);
		getPainelForm().add(painelCentro, BorderLayout.CENTER);
	}

	@Override
	protected void setupLayout() {
		super.setupLayout();

		getPainelForm().setLayout(new BorderLayout());

		painelNorte.setLayout(new BorderLayout());
		painelCentro.setLayout(new FlowLayout());
	}

	public void criarObjectTableModel() {
		tableModel = new ObjectTableModel<Cliente>(resolver, "nome,cpf");
	}

	@Override
	public void exibir() {
		setVisible(true);
	}

	@Override
	public void fechar() {
		dispose();
	}

	public static void main(String[] args) {
		new ClientePesquisa(null).exibir();
	}

}
